<!--
 * @Author: hongjianfeng
 * @Date: 2023-08-02 00:01:03
 * @LastEditors: hongjianfeng
 * @LastEditTime: 2023-08-02 00:01:04
 * @Description: 
-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>1</title>
    <meta
      name="viewport"
      content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
    />
    <link
      rel="stylesheet"
      type="text/css"
      href="https://lib.baomitu.com/normalize/4.2.0/normalize.min.css"
    />
  </head>

  <body>
    <div id="aaa">111</div>
    <script src="jquery.js"></script>
    <script
      type="text/javascript"
      src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"
    ></script>
    <script>
      // webview.postMessage({ data: { foo: "bar1" } });
    </script>
    <script>
      $(function () {});
      window.onload = function () {
        //     a = document.createElement("a");
        // a.setAttribute("href", "hlwdjk://weixin?test=1"); /***打开app的协议，有an同事提供***/
        // a.style.display = "none";
        // document.body.appendChild(a);
        // window.open('hlwdjk://weixin?test=1')
        // window.location.href = "hlwdjk://weixin?test=1";
        function getUrlParam(key, uurl) {
          if (uurl == null || uurl == "") {
            uurl = window.location.href;
          }
          var url = decodeURI(uurl);
          var paramMap = {};
          var firstIndex = url.indexOf("?");
          var paramStr = url.substring(firstIndex + 1);
          if (paramStr && paramStr != "") {
            var index = paramStr.indexOf("?"); //再次检查参数，避免后面有参数的值是访问地址
            var lastVal = "";
            var sflag = false; //标识有第二个问号
            if (index > 0) {
              var urlTemp = paramStr.substring(0, index);
              var lastIndex = urlTemp.lastIndexOf("=");
              lastVal = paramStr.substring(lastIndex + 1);
              paramStr = paramStr.substring(0, lastIndex + 1);
            }
            var paramStrArr = paramStr.split("&");
            for (var i = 0; i < paramStrArr.length; i++) {
              var temp = paramStrArr[i];
              var indexE = temp.indexOf("=");
              var pKey = temp.substring(0, indexE);
              var pVal = "";
              if (sflag && i == paramStrArr.length - 1) {
                pVal = lastVal;
              } else {
                pVal = temp.substring(indexE + 1);
              }
              paramMap[pKey] = pVal;
            }
          }
          return paramMap;
        }
        var params = getUrlParam();
        console.log(211, params);

        document.getElementById("aaa").onclick = function () {
          // 设置在此处单击#button时要发生的事件
          // uni.postMessage.postMessage({ data: params });
          wx.miniProgram.postMessage({ data: params });
        };
      };
      window.onhashchange = function () {
        alert(window.location.hash);
        console.log(22, window.location.hash); //获取当前hash值
      };
    </script>
    <style></style>
  </body>
</html>
